﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Drawing;
using System.Windows.Forms;
using System.Threading;

namespace eventModel
{
    /// <summary>This class sets up the System Tray Icon and is used for the UI console...</summary>
    class ServerInterface
    {
        public static NotifyIcon ntfyIcon { get; set; }
        public static ServerControl srvCntrl { get; set; }

        /// <summary>Sets up System Tray Icon..</summary>
        public static void InitializeSystemTrayIcon()
        {
            ntfyIcon = new System.Windows.Forms.NotifyIcon();
            ntfyIcon.Text = "Event Server";
            ntfyIcon.Visible = true;
            ntfyIcon.Icon = eventModel.Properties.Resources.icon;

            ntfyIcon.ContextMenuStrip = new ContextMenuStrip();

            ntfyIcon.ContextMenuStrip.Items.AddRange(new ToolStripItem[] { new ToolStripMenuItem() });
            ntfyIcon.ContextMenuStrip.Items[0].Text = "Manage";
            ntfyIcon.ContextMenuStrip.Items[0].Click += new EventHandler(Manage_Click);

            ntfyIcon.ContextMenuStrip.Items.AddRange(new ToolStripItem[] { new ToolStripMenuItem() });
            ntfyIcon.ContextMenuStrip.Items[1].Text = "Exit";
            ntfyIcon.ContextMenuStrip.Items[1].Click += new EventHandler(Exit_Click);

            Application.Run();
        }

        public static void Exit_Click(object sender, EventArgs e)
        {
            ntfyIcon.Visible = false;
            ServerEntry.AllowListen = false;
            Application.Exit();
        }

        static void Manage_Click(object sender, EventArgs e)
        {
            if (srvCntrl == null) { srvCntrl = new ServerControl(); }
            srvCntrl.ShowDialog();
        }

    }
}
